 
#ifndef __RSP_C_UPDATE__HEADER_FILE__
#define __RSP_C_UPDATE__HEADER_FILE__

#include "coid/comm/commtypes.h"
#include "coid/comm/dynarray.h"
#include "coid/comm/binstream/binstream.h"

#include "update.h"

using namespace coid;

struct rsp_c_controller;


////////////////////////////////////////////////////////////////////////////////
///Global RSP server settings
struct rsp_c_settings : rsp_settings
{
    int set_command_lag( int lag )
    {
        _cmdlag = lag;
        return _cmdlag;
    }

    void set_params( uint nwaiting )
    {
        rsp_settings::init( 0, nwaiting );
    }

    rsp_c_settings()
    {
        _cmdlag = 1;
    }

public:
    int  _cmdlag;                   ///< lag for keyboard commands, in frames
    dynarray<ushort> _wrk_cmdlengths;
};


extern rsp_c_settings  RSPC_SETTINGS;


////////////////////////////////////////////////////////////////////////////////
///Object containing the streamed updates, used by client
class rsp_c_update
{
public:

    binstream*  _bin;               ///< data stream for updates
    rsp_c_controller* _ctrl;

    uint _nsrvskip;                 ///< number of frames from server message to skip (already received)
    uint _maxcmd;

    uint _changed;                  ///< change count for incremental updates
    int _full;                      ///< full update

    ///Create rsp_c_update on client
    rsp_c_update( rsp_c_controller* ctrl, binstream& bin, int dack, int dcmd )
    {
        _ctrl = ctrl;
        _bin = &bin;

        _nsrvskip = dack;
        _maxcmd = !dcmd ? 1 : dcmd+RSPC_SETTINGS._nleading+RSPC_SETTINGS._cmdlag+1;
        //_finalcmd = !dcmd ? 1 : dcmd;
        _full = dcmd ? 0 : 1;

        _changed = 0;
    }
};


#endif //__RSP_C_UPDATE__HEADER_FILE__
